package com.base.common.exception;

import com.base.common.enums.ErrorEnum;
import lombok.Data;

/**
 * <p>作为项目开发过程中抛出运行时异常的基类存在，其他运行时异常继承自该类</p>
 *
 * @author admin
 * @date 2020/5/12 PM2:11
 */
@Data
public class CommonRuntimeException extends RuntimeException {
    private static final long serialVersionUID = -3812061084899240673L;

    private String code;

    /**
     * <p>Title: 构造器</p>
     * <p>Description: 带有程序异常与异常描述的构造</p>
     *
     * @param message 异常描述
     * @param cause   异常对象
     */
    public CommonRuntimeException(String message, Throwable cause) {
        super(message, cause);
    }

    /**
     * <p>Title: 构造器</p>
     * <p>Description:只带有异常描述的构造</p>
     *
     * @param message 异常描述
     */
    public CommonRuntimeException(String message) {
        super(message);
    }

    /**
     * @param message
     * @param code
     */
    public CommonRuntimeException(String message, String code) {
        super(message);
        this.code = code;
    }

    /**
     * @param errorEnum
     */
    public CommonRuntimeException(ErrorEnum errorEnum) {
        super(errorEnum.getCodeMsg());
        this.code = errorEnum.getCode();
    }

    /**
     * @param message
     * @param code
     */
    public CommonRuntimeException(String message, String code, Throwable e) {
        super(message, e);
        this.code = code;
    }
}